//package com.mayikt.classloader;
//
//import com.mayikt.service.OrderService;
//
//import java.io.File;
//
///**
// * @ClassName Test004
// * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
// * @Version V1.0
// **/
//public class Test004 {
//    private static long startTime;
//
//    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
//        MayiktClassLoader mayiktClassLoader = new MayiktClassLoader();
//        mayiktClassLoader.setFileObject(new File("E:\\code\\OrderServiceImpl.class"));
//        Class<?> aClass = mayiktClassLoader.findClass("com.mayikt.service.impl.OrderServiceImpl");
//        OrderService orderService = (OrderService) aClass.newInstance();
//        System.out.println("读取class成功：" + orderService.addOrder());
//
//        File fileObject = mayiktClassLoader.getFileObject();
//        startTime = fileObject.lastModified();
//        new Thread(() -> {
//            while (true) {
//                try {
//                    Thread.sleep(2000);
//                } catch (Exception e) {
//
//                }
//                long endTime = fileObject.lastModified();
//                if (endTime != startTime) {
//
//                    System.out.println("class文件发生了变化，需要重新读取");
//                    try {
//                        MayiktClassLoader newMayiktClassLoader = new MayiktClassLoader();
//                        newMayiktClassLoader.setFileObject(new File("E:\\code\\OrderServiceImpl.class"));
//                        Class<?> newClass = newMayiktClassLoader.findClass("com.mayikt.service.impl.OrderServiceImpl");
//                        OrderService newOrderService = (OrderService) newClass.newInstance();
//                        System.out.println("读取class成功：" + newOrderService.addOrder());
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                    startTime = endTime;
//                }
//            }
//        }).start();
//    }
//}
